package com.example.rvdemo.touchanddivider;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.rvdemo.R;

import java.util.ArrayList;
import java.util.List;

public class ClickAndDividerActivity extends Activity {
    private RecyclerView rv_touchanddivider;
    private List<String> datalist;
    private RVSimpleAdaptar rvSimpleAdaptar;
    private LinearLayoutItemDecoration linearLayoutItemDecoration;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.rv_touch);
        rv_touchanddivider = findViewById(R.id.rv_touchanddivider);
        linearLayoutItemDecoration = new LinearLayoutItemDecoration(this,R.drawable.rv_divider);
        datalist = new ArrayList<>();
        for (int i = 0; i < 50; i++) {
            datalist.add("I am "+i);
        }
        rvSimpleAdaptar = new RVSimpleAdaptar(this,datalist);
        rvSimpleAdaptar.setiItenClick(new RVSimpleAdaptar.IItenClick() {
            @Override
            public void onItenClick(int position) {
                Toast.makeText(ClickAndDividerActivity.this,"Click at "+position,Toast.LENGTH_SHORT).show();
            }
        });
        rvSimpleAdaptar.setiItemLongClick(new RVSimpleAdaptar.IItemLongClick() {
            @Override
            public boolean onItemLongClick(int position) {
                Toast.makeText(ClickAndDividerActivity.this,"LongClick at "+position,Toast.LENGTH_SHORT).show();
                return true;
            }
        });
        rv_touchanddivider.setAdapter(rvSimpleAdaptar);
        rv_touchanddivider.setLayoutManager(new GridLayoutManager(this,3));
//        rv_touchanddivider.setLayoutManager(new LinearLayoutManager(this));
//        rv_touchanddivider.addItemDecoration(linearLayoutItemDecoration);
        rv_touchanddivider.addItemDecoration(new GridLayoutItemDecoration(this,R.drawable.rv_divider));
    }
}
